package com.apes.fn.scm.merchant.settlement.model;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 * @BelongsProject: apes-server
 * @BelongsPackage: com.apes.fn.scm.merchant.settlement.model
 * @ClassName: CostSummary
 * @Author: pyb
 * @Description: 成本汇总
 * @CreateTime: 2020-10-28 17:35
 * @Version: 1.0
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicUpdate
@DynamicInsert
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = CostSummary.CONST_TABLE_NAME)
public class CostSummary extends BaseModel {
    public static final String CONST_TABLE_NAME = "fn_merchant_cost_summary";

    @Id
    @Column(name = "id", length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "赋能成本汇总", padding = 8)
    @Comment("编码")
    private String id;

    @NotNull
    @ManyToOne(optional = false)
    @JoinColumn(name = "merchant_settlement_id", referencedColumnName = "id")
    @Comment("赋能商户结算对账单")
    private MerchantSettlement merchantSettlement;


    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "cost_summary_type", referencedColumnName = "id")
    @Comment("成本汇总")
    private Enumeration costSummaryType;


    @Column(name = "previous_not_deducted", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("上期未扣收")
    private double previousNotDeducted=0 ;

    @Column(name = "current_period_should", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("本期应扣收")
    private double currentPeriodShouldDeducted=0 ;


    @Column(name = "current_period_actual", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("本期实际扣收")
    private double currentPeriodActualDeducted=0 ;

    @Column(name = "remaining_deductible_balance", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("剩余应扣余额")
    private double remainingDeductibleBalance=0 ;

    @Column(name = "form_id", length = 64)
    @Comment("表单编号")
    private String formId;

    @Transient
    private String totalCurrentCost;
}
